<%--
  Created by IntelliJ IDEA.
  User: kkk
  Date: 2022/8/2
  Time: 14:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .div{
            margin-left: 400px;
            width: 1000px;
            height: 500px;
        }
        table{
            background-color: darkgray;
            width: 720px;
        }
        .text{
            width: 150px    ;
        }
    </style>
    <base href="${pageContext.request.contextPath}/">
    <script src="js/jquery.js"></script>
</head>
<body>
    <div class="div">
        <form action="ResumeAddServlet" method="post">
            <h2 style="margin-left: 250px">添加个人简历信息</h2>
            <table border="1">
                <tr>
                    <td>姓名：</td>
                    <td><input class="text" id="userName" name="userName" type="text"><span id="spanName"></span></td>
                </tr>
                <tr>
                    <td>性别：</td>
                    <td>
                        <input type="radio" name="gender" value="男" checked>男
                        <input type="radio" name="gender" value="女">女
                    </td>
                </tr>
                <tr>
                    <td>籍贯地址：</td>
                    <td><input class="text" id="address" name="address" type="text"><span id="spanAddress"></span></td>
                </tr>
                <tr>
                    <td>出生日期：</td>
                    <td><input class="text" id="birth" name="birth" type="text">格式：yyyy—MM-dd<span id="spanBirth"></span></td>
                </tr>
                <tr>
                    <td>联系电话：</td>
                    <td><input class="text" id="phone" name="phone" type="text" name="phone" onblur="judgePhone(this.value)" ><span id="spanPhone"></span></td>
                </tr>
                <tr>
                    <td>毕业学校：</td>
                    <td><input class="text" id="school" name="school" type="text"><span id="spanSchool"></span></td>
                </tr>
                <tr>
                    <td>简历状态：</td>
                    <td>
                        <input type="radio" name="status" title="公开" value="1" checked> 公开
                        <input type="radio" name="status" title="保密" value="0">保密
                    </td>
                </tr>
                <tr>
                    <td>操作：</td>
                    <td>
                        <input type="submit" id="sub" value="新增">
                        <input type="button" onclick="javascript:history.back()" value="返回">
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <script>
        //为表单元素添加失去焦点事件
       $(function () {
           $('#userName').blur(checkUserName);
           $('#address').blur(checkAddress);
           $('#birth').blur(checkBirth);
           $('#phone').blur(checkPhone);
           $('#school').blur(checkSchool);
           $('form').submit(function () {
               if (checkUserName()===true && checkAddress()===true && checkBirth()===true && checkPhone()===true && checkSchool()===true) {
                   alert("添加成功")
               }else {
                   alert("添加失败")
               }
           })
       })

        //判断姓名是否为空
        function checkUserName() {
            if ($('#userName').val()==="") {
                $('#spanName').text("姓名不能为空！");
                return false;
            }
            return true;
        }

        //判断地址是否为空
        function checkAddress() {
            if ($('#address').val()==="") {
                $('#spanAddress').html("地址不能为空！");
                return false;
            }
            return true;
        }

        //判断生日是否为空
        function checkBirth() {
            var log=/^(19[2-9]\d{1})|(20((0[0-9])|(1[0-9])|(2[0-2])))$/
            if ($('#birth').val()==="") {
                $('#spanBirth').html("出生时间不能为空！");
                return false;
            }
            // else if(log.test($('#birth').val())===false){
            //     $('#spanBirth').html("时间格式不正确！");
            // }
            return true;
        }

        //判断手机是否为空
        function checkPhone() {
            if ($('#phone').val()==="") {
                $('#spanPhone').html("手机号不能为空！");
                return false;
            }
            return true;
        }

        //判断毕业学校是否为空
        function checkSchool() {
            if ($('#school').val()==="") {
                $('#spanSchool').html("毕业学校不能为空！");
                return false;
            }
            return true;
        }
        //判断手机号是否存在
        function judgePhone(phone){
            $.ajax({
                url:"ResumeCheckPhoneServlet",
                type:"GET",
                data:"phone="+phone,
                async:false,
                success:function (data) {
                    if (data==="true") {
                        alert("ftghjkl,; ")
                        $('#spanPhone').html("手机号已存在！");
                        $('#phone').val("");
                    }
                }
            })
        }
    </script>
</body>
</html>
